<?php
echo $this->load->view ( 'header' );
?>
<!--头部开始-->
<div>
	<ul class="breadcrumb">
		<li><a href="<?php echo site_url('main'); ?>"><?php echo lang('set_system'); ?></a><span
			class="divider">/</span></li>
		<li><a
			href="<?php echo site_url($this -> config -> item('admin_folder').'role'); ?>"><?php echo $title; ?></a></li>
	</ul>
</div>
<!--头部结束-->
<?php
if ($this->session->flashdata ( 'message' )) {
	$message = $this->session->flashdata ( 'message' );
}
if ($this->session->flashdata ( 'error' )) {
	$error = $this->session->flashdata ( 'error' );
}
if (function_exists ( 'validation_errors' ) && validation_errors () != '') {
	$error = validation_errors ();
}
?>
		
		<?php if (!empty($message)): ?>
<div class="alert alert-info">
	<a class="close" data-dismiss="alert">×</a>
			<?php echo $message; ?>
		</div>
<?php endif; ?>
						<?php if (!empty($error)): ?>
<div class="alert alert-error">
	<a class="close" data-dismiss="alert">×</a>
			<?php echo $error; ?>
		</div>
<?php endif; ?>

<!--角色列表开始-->
<div class="row-fluid">
	<div class="box span12">
		<div class="box-header well">
			<h2>
				<i class="icon-info-sign"></i> 管理查看权限--<?php echo $productName; ?></h2>
			<div class="box-icon">
				<a href="#" class="btn btn-minimize btn-round"><i
					class="icon-chevron-up"></i></a> <a href="#"
					class="btn btn-close btn-round"><i class="icon-remove"></i></a>
			</div>
		</div>
		<div class="box-content">
			<table
				class="table table-striped table-bordered bootstrap-datatable datatable">
				<thead>
					<tr>
						<th><?php echo "用户名"; ?></th>
						<th><?php echo "用户角色"; ?></th>
						<th><?php echo "操作"; ?></th>
					</tr>
				</thead>
				<tbody>
                <?php if($datas):?>
						  	   <?php foreach($datas as $n => $role_datas): ?>
							<tr>
						<td><?php echo $role_datas['username']; ?>	</td>
						<td><?php echo $role_datas['name']; ?>	</td>
						<td>
							<?php if($role_datas["statu"]==0):?>
							<a
							href="javascript:void(0)"
							class="product"
							data="<?php echo $role_datas["id"]; ?>"
							statu="0"
							title="<?php echo lang('role_edit'); ?>">已加入工程列表</a>
							<?php else:?>
								<a
							href="javascript:void(0)"
							class="product"
							data="<?php echo $role_datas["id"]; ?>"
							statu="1"
							title="<?php echo lang('role_edit'); ?>">未添加</a>
							<?php endif;?>
						</td>
					</tr>
					  <?php endforeach; ?>
                <?php else:?>
                    <tr><td colspan="10"><div class="center"><h4>无任何数据</h4></div></td></tr>
                <?php endif;?>
            </table>

		</div>
	</div>
</div>
<!--角色列表结束-->
<?php
echo $this->load->view ( 'footer' );
?>
<script type="text/javascript">
	$(document).ready(function(){
		$(".product").click(function(){
			console.log($(this).attr("statu"));
			if ($(this).attr("statu")=="1") {
				var user = $(this);
				$.post("/admin/product/adduser/"+$(this).attr("data") + "/"+<?php echo $pid;?>, function(data) {
					var message_data = $.parseJSON(data);
					if (message_data['msg'] == 1) {
						$(user).attr("statu","0");
						$(user).html("已加入工程列表");
					}
				});
			}else{
				var user = $(this);
				$.post("/admin/product/deleteuser/"+$(this).attr("data") + "/"+<?php echo $pid;?>, function(data) {
					var message_data = $.parseJSON(data);
					if (message_data['msg'] == 1) {
						$(user).attr("statu","1");
						$(user).html("未添加");
					}
				});
			}
		})
		
	})
</script>
</body>
</html>
